package com.nbsaas.boot.storage.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.code.annotation.data.Dict;
import com.nbsaas.boot.code.annotation.data.DictItem;
import com.nbsaas.boot.jpa.data.entity.LongEntity;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "common_store_file")
@org.hibernate.annotations.Table(appliesTo = "common_store_file", comment = "文件")
@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "文件", model = "订单")
public class File extends LongEntity {

    @FormField(title = "文件名称", grid = true, width = "200")
    @Column(length = 50)
    @SearchItem(label = "文件名称", name = "name")
    @Comment("文件名称")
    private String name;

    @Comment("服务端地址")
    private String serverUrl;

    @Comment("文件地址")
    private String url;

    @FormField(title = "对象存储key", grid = true, width = "400")
    @Comment("对象存储key")
    private String objectKey;

    @Comment("上级文件")
    @JoinColumn(name = "parent_id")
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private File parent;

    @OneToMany(fetch = FetchType.LAZY,mappedBy = "parent")
    private List<File> children;

    @FormField(title = "文件类型 1:文件, 2:文件夹", grid = true)
    @Dict(items = {@DictItem(value = 1, label = "文件"), @DictItem(value = 2, label = "文件夹")})
    @Comment("文件类型")
    private Integer fileType;

    @Column(length = 20)
    @Comment("文件扩展名")
    private String extensionName;

    @FormField(title = "文件大小", grid = true)
    @Comment("文件大小")
    private Long fileSize;


    @Comment("创建人id")
    private Long creatorId;

    @Column(length = 30)
    @Comment("创建人姓名")
    @FormField(title = "创建人", grid = true, col = 22)
    private String creatorName;

    @Comment("租户id")
    private Long tenantId;

    @FormField(title = "创建时间", grid = true, width = "160", ignore = true)
    @Comment("创建时间")
    private Date addDate;

    @Comment("最新修改时间")
    private Date lastDate;
}
